package com.demo.my;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;

public class RenderHtmlController extends Controller {
	
	private static String UeHtmlStoreDir = null;
	private static int seed = 101;

	public void camouflage(){
		String htmlContent = getPara("content");
		renderHtml(htmlContent);
	}
	
	public void saveUeHtml(){
		String htmlContent = getPara("content");
		BufferedWriter bw = null;
		
		if(null == UeHtmlStoreDir){
			UeHtmlStoreDir = PropKit.get("UeHtmlStoreDir");
		}
		
		String sp = File.separator;
		String suffix = ".html";
		
		File file = new File( UeHtmlStoreDir + sp + "html_" + (seed++) + suffix);
		try {
			bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
			bw.write(htmlContent);
			bw.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(null != bw){
					bw.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		renderJson("success");
	}
	
	
}
